from model import BaseModel, models
from role.models import Roles


class Users(BaseModel):
    """
    用户表
    """
    username = models.CharField(max_length=20, unique=True, verbose_name="用户名")
    password = models.CharField(max_length=256, verbose_name="密码")
    phone = models.CharField(max_length=11, verbose_name="手机号")
    email = models.EmailField(max_length=64, verbose_name="邮箱")
    nickname = models.CharField(max_length=32, verbose_name="真实姓名")
    avatar = models.CharField(max_length=128, null=True, blank=True, verbose_name="用户头像")
    last_login = models.DateTimeField(blank=True, null=True, verbose_name="上次登录时间")

    class Meta:
        db_table = 'users'
        verbose_name = '用户信息'
        verbose_name_plural = verbose_name


class UserToRole(models.Model):
    user = models.ForeignKey(to=Users, on_delete=models.CASCADE)
    role = models.ForeignKey(to=Roles, on_delete=models.CASCADE)

    class Meta:
        db_table = 'user_to_role'
        verbose_name = '用户角色多对多表'
        verbose_name_plural = verbose_name
